#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 1e6;

int n;
vector<int> adj[maxn];
inline void add(int l, int r) { adj[l].push_back(r); }

int dis[maxn];
int f[maxn][2];

void dfs(int u, int p) {
    dis[u] = dis[p] + 1;
    f[u][0] = dis[u], f[u][1] = dis[u];
    for (auto v : adj[u]) {
        if (v == p) continue;
        dfs(v, u);
        f[u][0] = min(min(f[u][1] + f[v][0] - dis[u],
                          f[u][0] + f[v][1] - dis[u] + 1),
                      f[u][0] + f[v][0]);
        f[u][1] += f[v][1] - dis[u] + 1;
    }
}

inline void init() {
    for (int i = 0; i <= n; ++i)
        adj[i].clear();
    for (int i = 0; i <= n; ++i)
        dis[i] = 0;
    for (int i = 0; i <= n; ++i)
        f[i][0] = 0, f[i][1] = 0;
    dis[0] = -1;
}

#define show(s, t, a) for (int i = s; i <= t; ++i) printf("%d ", a); puts("");

int main() {
    int Q = rad();
    rf(q, Q) {
        n = rad();
        init();
        for (int i = 2; i <= n; ++i) {
            int tmp = rad();
            add(i, tmp), add(tmp, i);
        }
        dfs(1, 0);
        // show(1, n, f[i][0]);
        // show(1, n, f[i][1]);
        // show(1, n, dis[i]);


        printf("Case #%d: %d\n", q, f[1][0]);
    }
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}

/*
1
10
1 1 3 3 5 5 7 8 6

1 
4
1 1 2
*/